<template>
  <base-breadcrumb :title="$route.meta.title">
    <!-- 质量验收记录维护 -->
    <a-card :bordered="false" style="margin-bottom:50px">
      <title-name title="基本信息"></title-name>
      <!-- 表单信息 -->
      <custom-form isValidate :formList="formList" :form="form" editModel="V">
        <!-- 需整改项 -->
        <template #rectificationItems>
          <s-table
            ref="table"
            tableLayout="fixed"
            size="default"
            rowKey="index"
            :columns="columns"
            :data="loadData"
            :alert="true"
            :showPagination="false"
          >
            <template slot="fileArrays" slot-scope="text, record">
              <file-link :fileList="record.fileArrays"></file-link>
            </template>
            <span slot="action" slot-scope="text, record">
              <a-button @click="handleManage(record)" type="primary">{{
                record.statusCode === '0' ? '填报' : '修改'
              }}</a-button>
            </span>
          </s-table>
        </template>
        <template #workUtilsName="scope">
          <div class="text_name">
            <ellipsis tooltip :length="40">{{ scope.data.value && scope.data.value.join(',') }}</ellipsis>
          </div>
        </template>
        <!-- 相关附件 -->
        <template #fileArrays="scope">
          <div class="text_name" v-if="!scope.data.value || scope.data.value.length < 1">无</div>
          <div v-else>
            <l-table
              uploadType="image"
              disabled
              :editModel="editModel"
              :uploadArrys.sync="scope.data.value"
              multiple
            ></l-table>
          </div>
        </template>
      </custom-form>
    </a-card>
    <!-- 页脚操作栏 -->
    <div
      class="btn_box page-btn-right-top"
    >
      <BasePrintButton
        v-if="editModel == 0"
        :beforePrintFn="() => getPritContent('CSCEC8XN-EQ-B30608')"
        class="button_right"
      />
      <a-button type="primary" @click="$multiTab.close()">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>

<script>
import { STable, Ellipsis } from '@/components' // 表格
import { acceptanceRecord } from '@/api/quality/quality' // api
import BaseEditPage from '@/views/baseEditPage' // 编辑详情页基础配置
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮

export default {
  name:'a'+ Date.now(),
  extends: new BaseEditPage(),
  components: {
    STable,
    Ellipsis,
    BasePrintButton,
  },
  data() {
    return {
      loading: false,
      id: '',
      editModel: '0',
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        if (this.editModel != 2) {
          this.loading = true
          return acceptanceRecord
            .getDetail({
              id: this.id,
              historyId: this.historyId,
            })
            .then((res) => {
              this.loading = false
              if (res.data) {
                this.form = res.data
                this.form.bpName = this.form.branchCompanyName + '/' + this.form.projectName
                return {
                  data: res.data.rectificationItems.map((item, index) => {
                    item.index = index + 1
                    return item
                  }),
                }
              }
            })
            .catch((res) => {
              this.loading = false
            })
        }
        // 深拷贝回调对象
      },
      columns: [
        {
          title: '部位',
          ellipsis: true,
          dataIndex: 'position',
        },
        {
          title: '问题',
          ellipsis: true,
          dataIndex: 'problem',
        },
        {
          title: '类别',
          ellipsis: true,
          dataIndex: 'categoryName',
        },
      ],
      form: {
        bpName: ''
      }, // 表单
    }
  },
  computed: {
    formList() {
      return [
        // {
        //   keyName: 'branchCompanyName',
        //   label: '所属分公司',
        // },
        // {
        //   keyName: 'projectName',
        //   label: '所属项目',
        // },
        {
          label: '所属单位',
          type: 'orgTree',
          keyName: 'projectId',
          span: 16,
          isNoBorder: true,
          viewName: "bpName",
        },
        {
          keyName: 'detailsName',
          label: '所属计划',
        },
        {
          keyName: 'checkAcceptanceTypeName',
          label: '验收类型',
        },
        {
          keyName: 'unitEngineering',
          label: '验收内容',
        },
        {
          keyName: 'subItemName',
          label: '分部分项',
        },
        {
          keyName: 'wbsName',
          label: 'WBS',
        },
        {
          keyName: 'acceptanceDatePlan',
          label: '计划验收时间',
        },
        {
          keyName: 'acceptanceDate',
          label: '验收时间',
        },
        {
          keyName: 'workUtilsName',
          label: '作业单位',
          slot: true,
        },
        {
          keyName: 'acceptorName',
          label: '验收负责人',
        },
        {
          keyName: 'acceptanceResult',
          label: '验收结果',
        },
        {
          keyName: 'rectificationItems',
          hidden: this.form.acceptanceResultCode == 0,
          label: '需整改项',
          slot: true,
          span: 24,
        },
        {
          keyName: 'fileArrays',
          label: '相关附件',
          slot: true,
          span: 24,
        },
      ]
    }, // 表单列表
  },
}
</script>
<style scoped>
.text_name {
  margin-top: -3px;
}
</style>
